package com.tongfusoft.document.web.securityc.service.impl;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.tongfusoft.document.manager.user.service.IDocumentUserService;

@Service("documentUserDetailsService")
public class DocumentUserDetailsServiceImpl implements UserDetailsService {

	@Autowired
	@Qualifier(value="DocumentUserService")
	public IDocumentUserService securityService;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
		// 得到用户的权限
		Collection<GrantedAuthority> auths = securityService.loadUserAuthoritiesByName(username);

		return new User(username, securityService.getPwdByName(username), true, true, true, true, auths);
	}

}
